package com.yanqu.road.dao.impl.activity.jieshi;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.activity.jieshi.config.*;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.HashMap;
import java.util.Map;

public class JieShiConfigDaoImpl extends TempDao {

    private static String getLightMarketMainLvConfigSql = "select * from `t_s_activity_lightmarket_mainlv` where `activityId`=? ORDER BY `level` ASC";

    public Map<Integer, LightMarketMainLvConfig> getLightMarketMainLvConfigList(int activityId) {
        Map<Integer, LightMarketMainLvConfig> map = new HashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getLightMarketMainLvConfigSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                LightMarketMainLvConfig lightMarketMainLvConfig = new LightMarketMainLvConfig();
                lightMarketMainLvConfig.setActivityId(rs.getInt("activityId"));
                lightMarketMainLvConfig.setLevel(rs.getInt("level"));
                lightMarketMainLvConfig.setUpCost(rs.getString("upCost"));
                lightMarketMainLvConfig.setBuildMaxNum(rs.getInt("buildMaxNum"));
                lightMarketMainLvConfig.setBuildTypeMaxNum(rs.getString("buildTypeMaxNum"));
                map.put(lightMarketMainLvConfig.getLevel(), lightMarketMainLvConfig);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }

    private static String getLightMarketShopConfigSql = "select * from `t_s_activity_lightmarket_shop` where `activityId`=? ORDER BY `id` ASC";

    public Map<Integer, LightMarketShopConfig> getLightMarketShopConfigList(int activityId) {
        Map<Integer, LightMarketShopConfig> map = new HashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getLightMarketShopConfigSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                LightMarketShopConfig lightMarketShopConfig = new LightMarketShopConfig();
                lightMarketShopConfig.setActivityId(rs.getInt("activityId"));
                lightMarketShopConfig.setId(rs.getInt("id"));
                lightMarketShopConfig.setType(rs.getInt("type"));
                lightMarketShopConfig.setArea(rs.getString("area"));
                lightMarketShopConfig.setMoney(rs.getString("money"));
                lightMarketShopConfig.setFood(rs.getInt("food"));
                lightMarketShopConfig.setForce(rs.getInt("force"));
                lightMarketShopConfig.setEffectType(rs.getInt("effectType"));
                lightMarketShopConfig.setEffect(rs.getString("effect"));
                map.put(lightMarketShopConfig.getId(), lightMarketShopConfig);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }


    private static String getLightMarketPatronConfigSql = "select * from `t_s_activity_lightmarket_parton` where `activityId`=? ORDER BY `level` ASC";

    public Map<Integer, LightMarketPatronConfig> getLightMarketPatronConfigList(int activityId) {
        Map<Integer, LightMarketPatronConfig> map = new HashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getLightMarketPatronConfigSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                LightMarketPatronConfig lightMarketPatronConfig = new LightMarketPatronConfig();
                lightMarketPatronConfig.setActivityId(rs.getInt("activityId"));
                lightMarketPatronConfig.setLevel(rs.getInt("level"));
                lightMarketPatronConfig.setCost(rs.getString("cost"));
                lightMarketPatronConfig.setEffect1(rs.getInt("effect1"));
                lightMarketPatronConfig.setEffect2(rs.getInt("effect2"));
                lightMarketPatronConfig.setPartonNum(rs.getInt("partonNum"));
                lightMarketPatronConfig.setVisitPro(rs.getInt("visitPro"));
                map.put(lightMarketPatronConfig.getLevel(), lightMarketPatronConfig);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }


    private static String getLightMarketRhythmConfigSql = "select * from `t_s_activity_lightmarket_rhythm` where `activityId`=? ORDER BY `round` ASC";

    public Map<Integer, LightMarketRhythmConfig> getLightMarketRhythmConfigList(int activityId) {
        Map<Integer, LightMarketRhythmConfig> map = new HashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getLightMarketRhythmConfigSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                LightMarketRhythmConfig lightMarketRhythmConfig = new LightMarketRhythmConfig();
                lightMarketRhythmConfig.setActivityId(rs.getInt("activityId"));
                lightMarketRhythmConfig.setRound(rs.getInt("round"));
                lightMarketRhythmConfig.setStandardForce(rs.getInt("standardForce"));
                lightMarketRhythmConfig.setStandardMoneySpeed(rs.getString("standardMoneySpeed"));
                lightMarketRhythmConfig.setEventParam1(rs.getString("eventParam1"));
                lightMarketRhythmConfig.setEventParam2(rs.getString("eventParam2"));
                map.put(lightMarketRhythmConfig.getRound(), lightMarketRhythmConfig);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }


    private static String getLightMarketEventConfigSql = "select * from `t_s_activity_lightmarket_event` where `activityId`=? ORDER BY `id` ASC";

    public Map<Integer, LightMarketEventConfig> getLightMarketEventConfigList(int activityId) {
        Map<Integer, LightMarketEventConfig> map = new HashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getLightMarketEventConfigSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                LightMarketEventConfig lightMarketEventConfig = new LightMarketEventConfig();
                lightMarketEventConfig.setActivityId(rs.getInt("activityId"));
                lightMarketEventConfig.setId(rs.getInt("id"));
                lightMarketEventConfig.setType(rs.getInt("type"));
                lightMarketEventConfig.setEventParam(rs.getString("eventParam"));
                lightMarketEventConfig.setEventText(rs.getString("eventText"));
                lightMarketEventConfig.setRewards(rs.getString("rewards"));
                lightMarketEventConfig.setWeight(rs.getInt("weight"));
                map.put(lightMarketEventConfig.getId(), lightMarketEventConfig);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }

}
